/**
 * 
 */
package neptune.web.client.view.components.dialogs;

import org.gwt.mosaic.ui.client.Caption;
import org.gwt.mosaic.ui.client.ImageButton;
import org.gwt.mosaic.ui.client.WindowPanel;
import org.gwt.mosaic.ui.client.Caption.CaptionRegion;

import com.google.gwt.user.client.DOM;
import com.google.gwt.user.client.ui.ClickListener;
import com.google.gwt.user.client.ui.Frame;
import com.google.gwt.user.client.ui.Widget;

/**
 * @author Roberto Bifulco [RobertoBifulco.it] [info@robertoBifulco.it]
 * 
 */
public class HelpDialog extends WindowPanel {

	public HelpDialog(String helpURL) {

		setCaption("Help");
		setPixelSize(500, 500);
		setAnimationEnabled(true);

		Frame frame = new Frame(helpURL);
		DOM.setStyleAttribute(frame.getElement(), "border", "none");
		setWidget(frame);

		addMaximizeButton(this, CaptionRegion.RIGHT);
		addMinimizeButton(this, CaptionRegion.RIGHT);
	}

	private void addMaximizeButton(final WindowPanel windowPanel,
			CaptionRegion captionRegion) {
		final ImageButton maximizeBtn = new ImageButton(Caption.IMAGES
				.windowMaximize());
		maximizeBtn.addClickListener(new ClickListener() {
			public void onClick(Widget sender) {
				if (windowPanel.getWindowState() == WindowState.MAXIMIZED) {
					windowPanel.setWindowState(WindowState.NORMAL);
				} else {
					windowPanel.setWindowState(WindowState.MAXIMIZED);
				}
			}
		});
		windowPanel.addWindowStateListener(new WindowStateListener() {
			public void onWindowStateChange(WindowPanel sender) {
				if (sender.getWindowState() == WindowState.MAXIMIZED) {
					maximizeBtn.setImage(Caption.IMAGES.windowRestore()
							.createImage());
				} else {
					maximizeBtn.setImage(Caption.IMAGES.windowMaximize()
							.createImage());
				}

			}
		});
		windowPanel.getHeader().add(maximizeBtn, captionRegion);
	}

	/**
	 * 
	 * @param windowPanel
	 */
	private void addMinimizeButton(final WindowPanel windowPanel,
			CaptionRegion captionRegion) {
		final ImageButton minimizeBtn = new ImageButton(Caption.IMAGES
				.windowMinimize());
		minimizeBtn.addClickListener(new ClickListener() {
			public void onClick(Widget sender) {
				windowPanel.setWindowState(WindowState.MINIMIZED);
			}
		});
		windowPanel.getHeader().add(minimizeBtn, captionRegion);
	}

}
